<?php

namespace app\adminapi\controller\reimbursement;

use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\reimbursement\ExpenseTypeLists;
use app\adminapi\logic\reimbursement\ExpenseTypeLogic;
use app\adminapi\validate\reimbursement\ExpenseTypeValidate;
use think\response\Json;

class ExpenseTypeController extends BaseAdminController
{
    /**
     * @notes 获取申请类型列表
     * @return Json
     */
    public function lists()
    {
        return $this->dataLists(new ExpenseTypeLists());
    }

    /**
     * @notes 添加申请类型
     * @return Json
     * @author
     * @date
     */
    public function add()
    {
        $params = (new ExpenseTypeValidate())->post()->goCheck('add');
        $result = ExpenseTypeLogic::add($params);
        if ($result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(ExpenseTypeLogic::getError());
    }

    /**
     * @notes 编辑申请类型
     * @return Json
     * @author
     * @date
     */
    public function edit()
    {
        $params = (new ExpenseTypeValidate())->post()->goCheck('edit');
        $result = ExpenseTypeLogic::edit($params);
        if ($result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(ExpenseTypeLogic::getError());
    }

    /**
     * @notes 删除申请类型
     * @return Json
     * @author
     * @date
     */
    public function delete()
    {
        $params = (new ExpenseTypeValidate())->post()->goCheck('id');
        $result = ExpenseTypeLogic::delete($params['id']);
        if ($result) {
            return $this->success('删除成功', [], 1, 1);
        }
        return $this->fail(ExpenseTypeLogic::getError());
    }



    /**
     * @notes 获取所有申请类型列表(用于下拉选择)
     * @return Json
     * @author
     * @date
     */
    public function getExpenseTypes()
    {
        $result = ExpenseTypeLogic::getAllExpenseTypes();
        return $this->success('获取成功', $result);
    }


    /**
     * @notes 查看申请类型详情
     * @return Json
     * @author
     * @date
     */
    public function detail()
    {
        $params = (new ExpenseTypeValidate())->goCheck('id');
        $result = ExpenseTypeLogic::detail($params['id']);
        return $this->success('获取成功', $result);
    }

}